package polyv_player;

import android.content.Intent;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;

/**
 * This class echoes a string called from JavaScript.
 */
public class polyv_plugin extends CordovaPlugin {

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("coolMethod")) {
            String message = args.getString(0);
            Log.i("polyv-plugin", "coolMethod");
            this.coolMethod(message, callbackContext);
            return true;
        }
        if (action.equals("play")) {
            String message = args.getString(0);
            Log.i("polyv-plugin", "play");
            this.coolMethod(message, callbackContext);
            return true;
        }
        return false;
    }

    private void coolMethod(String message, CallbackContext callbackContext) {
        if (message != null && message.length() > 0) {
            callbackContext.success(message);
        } else {
            callbackContext.error("Expected one non-empty string argument.");
        }
    }

//    private void play(String message, CallbackContext callbackContext) {
//        Intent intent = PolyvPlayerActivity.newIntent(context, PolyvPlayerActivity.PlayMode.landScape, vid, PolyvBitRate.ziDong.getNum(),false);//newIntent(context, PolyvPlayerActivity.PlayMode.landScape, vid);
//        intent.putExtra(PolyvMainActivity.IS_VLMS_ONLINE, false);
//        context.startActivity(intent);
//    }
}
